﻿<cfmodule template="../../tag/layout.cfm" bodyIsEasyUILayout="false">
<script type="text/javascript" charset="utf-8" src="ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="ueditor/lang/zh-cn/zh-cn.js"></script>
<form method="post" class="form">
  <fieldset>
    <legend>基本信息</legend>
    <table class="table" width="100%">
      <tbody>
        <tr>
          <th>编号</th>
          <td><input name="id" readonly /></td>
        </tr>
        <tr>
          <th>门店名称</th>
          <td><input name="name" class="easyui-validatebox" data-options="required:true" /></td>
        </tr>
        <tr>
          <th>门店地址</th>
          <td><input name="address" class="easyui-validatebox" data-options="required:true" style="width:500px;"/></td>
        </tr>
        <tr>
          <th>联系电话</th>
          <td><input name="phone"/></td>
        </tr>
        <tr>
          <th>联系人</th>
          <td><input name="linkman"/></td>
        </tr>
        <tr>
        <th>门店图片</th>
	      <td>
	      	<select class="selectFiles"><option>选择文件</option></select>
	      	<a href="#" class="easyui-linkbutton uploader" data-options="iconCls:'icon-add'">选择文件</a>
	      	<input name="pic" class="selectFilesValue" type="hidden" />
	      </td>
        </tr>
		<tr>
          <th>门店介绍</th>
          <td>
          	<textarea id="content" name="content" style="width:500px; height:180px;"></textarea>
          	<input type='button' mode='0' class='editor' onclick="EditorRender('content',$(this))" value='切换至编辑器'>
          </td>
        </tr>
      </tbody>
    </table>
  </fieldset>
</form>

</cfmodule>
<cfscript>
	if( structKeyExists(rc, "id")  && rc.id > 0 ){
		id = rc.id;
	}else{
		id = 0;
	}
</cfscript>

<script type="text/javascript">
	var closeDialog = function($dialog) {
		$dialog.dialog('destroy');
	}

	var submitNow = function($dialog, $grid, $pjq) {
		var url;
		if ($(':input[name="id"]').val().length > 0) {
			url = '?action=store.update'; //更新操作
		} else {
			url = '?action=store.save';	//新增操作
		}
		$.post(url, fw.serializeObject($('form')), function(result) {
			if (result) {
				$grid.datagrid('reload');
				$dialog.dialog('destroy');
			}
		}, 'json');
	};

	var submitForm = function($dialog, $grid, $pjq) {
		if ($('form').form('validate')) {
			submitNow($dialog, $grid, $pjq);
		}
	};

	//加载数据，初始进度条
	parent.$.messager.progress({
		text : '数据加载中....'
	});

	$(function(){
		$(".uploader").on('click',uploaderFun);

		$.ajax({
		    type: "POST",
		    url: "?action=store.get",
		    data: {
		        id:<cfoutput>#id#</cfoutput>
		    }
		}).done(function(result) {
			$('form').form('load', result);


			//pic字段内容
			var selectObj = $('.selectFiles');
			var options = "<option>选择文件</option>";

			$.ajax({
				type: "POST",
			    url: "?action=uploader.gets",
			    data:{ids:result.pic}
			}).done(function(p){
				//对返回结果进行遍历，重组option选项，并将结果放置到相应的selectOption对象中去
				$(p).each(function(){
					options +="<option>" + this.clientname + "</option>";
				})
				selectObj.html(options);
			})


			parent.$.messager.progress('close');
		}, 'json');
	})
</script>
